var ct_type, ct_size;
var containers;
function getDropdownValueCt(url) {
    var tmp = new Array();
    $.ajax({
        url: url, async: false,
        success: function (data, textStatus, jqXHR) {
            $.each(data.results, function (i, n) {
                tmp.push(n[0]);
            });
        }
    });
    return tmp;
}
function initDropdown() {
    var typeobj = $("#containers li:first span .ct_type:not(.ui-autocomplete-input)")
        .autocomplete({
            source: ct_type,
            minLength: 0,
            open: function (event, ui) {
                $(this).autocomplete("widget").find("a")
                    .css("height", "20px");
            }
        });
    var sizeobj = $("#containers li:first span .ct_size:not(.ui-autocomplete-input)")
        .autocomplete({source: ct_size, minLength: 0});
    $(typeobj).val(ct_type[1]);//设置默认显示的柜型
    $(sizeobj).val(ct_size[0]);
    initDropdownEven(typeobj);
    initDropdownEven(sizeobj);
    initDropdownStyle(typeobj);
    initDropdownStyle(sizeobj);
}
function initDropdownEven(obj) {
    $(obj).bind('click', function () {
        $(this).autocomplete('search', '');
    });
    $(obj).bind('focus', function () {
        $(this).autocomplete('search', '');
    });
}
function initDropdownStyle(obj) {
    $(obj).attr("readonly", "readonly");
    $(obj).addClass('ui-state-default ui-corner-all');
    $(obj).css({"margin": "1px", "text-align": "center"});
}

function initGoodAddressTable(containers) {
    var trs = $("#tril_goodsList tr");
    $.each(trs, function (i, n) {
        if (i != 0) {
            var ctnumtype = $($(n).find("td")[7]).text();
            var ids = "";
            $.each(containers, function (i, m) {
                var tmp = ctnumtype.replace(m.id, m.index);
                // 因为不是每一个柜都会被一次选择，所以需要处理
                if (tmp != ctnumtype) {
                    ids += m.id + ",";
                    ctnumtype = tmp;
                }
            });
            if (ids) {
                ids = ids.substr(0, ids.length - 1);
            }
            $($(n).find("td")[7]).text(ctnumtype);
            $($(n).find("td")[10]).text(ids);
        }
    });
}

var showTrail = false;


function initCtNumTypeDropdown(containers) {
    $("input[id^='gd_ctNumType']").each(function (index, element) {
        var n = (index == 0 ? "" : "_" + index);
        $("#gd_ctNumType" + n).autocomplete({
            minLength: 0,
            source: containers,
            select: function (event, ui) {
                return false;
            },
            open: function (event, ui) {
                var dropdownMenu = $(this).autocomplete("widget");
                dropdownMenu.children().click(function () {
                    // 获取checkbox对象
                    var selectObj = $($(this).children().first()).children()
                        .first();
                    // 获取checkbox旁边的那个显示值
                    var textValue = $(this).text();
                    //var inputObj = $("#gd_ctNumType"+n);
                    var inputObj = $("#gd_ctNumType_show" + n);
                    // 获取输入框的值
                    var inputValue = inputObj.text();
                    // 点击前前状态为选中时
                    if (selectObj.attr("checked")) {
                        // 设置显示值
                        selectObj.attr("checked", false);// 改成未选中
                        var tmpVal = "," + textValue;
                        var index = inputValue.indexOf(tmpVal);
                        // 处理值，当前选择的值不是最开选择的值
                        if (index != -1) {
                            // 将当前选择的值和","移除
                            inputObj.html(inputValue.substr(0, index) + inputValue
                                    .substr(index + tmpVal.length));
                            // 处理值，当前选择的值是最开始选择的值
                        } else if (inputValue.indexOf(textValue) == 0) {
                            // 将当前选择中的值和","移除
                            inputObj.html(inputValue.substr(textValue.length + 1));
                        }
                        // 点击前为未选中状态
                    } else {
                        // 设置显示值
                        selectObj.attr("checked", true);// 改成选中
                        var v = inputValue;
                        if (inputValue != "") {
                            v += ",";// 如果下拉框已经有值就先加个","
                        }
                        v += textValue;// 附加上选择的值
                        inputObj.html(v);// 给输入框赋值
                    }
                    countSizeType(inputObj, n, "");
                });
                dropdownMenu.find("input[type='checkbox']").click(function () {
                    // checkbox的点击会触发
                    // li的点击事件，所以需要在点击的时候先将checkbox的选中状态处理成相反的
                    if ($(this).attr("checked")) {
                        $(this).attr("checked", false);
                    } else {
                        $(this).attr("checked", true);
                    }
                });
            },
            close: function (event, ui) {
                try {
                    var source = $(event.srcElement).parent();
                    if (source.hasClass("ui-menu-item") || $(event.srcElement)
                            .is("input[type='checkbox']")) {
                        $(this).autocomplete("widget").show();
                    }
                } catch (e) {
                }
            }
        }).data("autocomplete")._renderItem = function (ul, item) {
            //var value = $(this.element).val();
            var value = $("#gd_ctNumType_show" + n).text();
            var checked = "";
            var id = item.index;
            if (value) {
                var index1 = value.indexOf(id + "号柜-" + item.size + "'" + item.type);
                var index2 = value.indexOf("," + id + "号柜-" + item.size + "'" + item.type);
                if (index1 == 0 || (index1 != 0 && index2 != -1)) {
                    checked = "checked";
                }
            }
            var checkbox = "";
            if (checked) {
                checkbox = "<a><input type='checkbox' value='" + id + "' checked='checked+' />" + id + "号柜-" + item.size + "'" + item.type + "</a>";
            } else {
                checkbox = "<a><input type='checkbox' value='" + id + "' />" + id + "号柜-" + item.size + "'" + item.type + "</a>";
            }

            var li = $("<li>").append(checkbox);
            return li.appendTo(ul);
        };
        initDropdownEven($("#gd_ctNumType" + n));
    });
}
/**
 * 请选择柜添加全选
 */
function selectAll(obj) {
    var obj_id = $(obj).attr("id");
    var n = "";
    if (obj_id) {
        n = obj_id.split("_")[2];
    }
    if (!n || n == "") {
        n = "";
    } else {
        n = "_" + n;
    }
    $("#gd_ctNumType" + n).focus();
    $("#gd_ctNumType" + n).blur();
//	var selectAll = $("#trial_gd_input tr:eq(1) td input[type='checkbox']").is(':checked');
    var selectAll = $("#selectall_checkbox" + n).is(':checked');
    var inputs = $("#gd_ctNumType" + n).autocomplete("widget").find("input");
    var value = "";
    if (selectAll == false) {
        for (var i = 0; i < inputs.length; i++) {
            $("#gd_ctNumType" + n).autocomplete("widget").find("input").eq(i).attr("checked", false);
        }
        $("#gd_ctNumType" + n).val("");
        $(obj).parent().parent().find("span[id^='gd_ctNumType_show']").text("");
    } else {
        for (var i = 0; i < inputs.length; i++) {
            $("#gd_ctNumType" + n).autocomplete("widget").find("input").eq(i).attr("checked", true);
            value += $("#gd_ctNumType" + n).autocomplete("widget").find("input").eq(i).parent("a").eq(0).text();
            if (i != inputs.length - 1) {
                value += ",";
            }
        }
        $("#gd_ctNumType_show" + n).text(value);
        countSizeType($("#gd_ctNumType_show" + n), n, "");
        //$("#gd_ctNumType").val(value);
    }

}


/**
 * 统计柜总数
 */
function countTotalSizeType() {
    var sizeType = new Array();
    var number = $("#tril_goodsList").find("tr").length;
    if (number <= 1) {
        return;
    }
    var strTemp = "";
    for (; number > 1; number--) {
        strTemp += $("#tril_goodsList").find("tr").eq(number - 1).find("td").eq(8).text();
//		strTemp += $("#tril_goodsList tr:eq("+number-1+") td:eq(8)").text();
        strTemp += ",";
    }
    strTemp = strTemp.substring(0, strTemp.length - 1);
    sizeType = strTemp.split(",");
    //去重
    var tempArray = [];
    var tempObj = {};
    for (var i = 0; i < sizeType.length; i++) {
        if (!tempObj[sizeType[i]]) {
            tempArray.push(sizeType[i]);
            tempObj[sizeType[i]] = 1;
        }
    }
    sizeType = tempArray;
    //计算相同柜的总数
    tempArray = [];
    var str = sizeType.join("-");
    sizeType = [];
    tempArray = str.split("-");
    for (var i = 0; i < tempArray.length; i += 2) {
        sizeType.push(tempArray[i + 1]);
    }
    sizeType.sort();
    var result = "";
    for (var i = 0; i < sizeType.length;) {
        var n = 1;
        var number = 1;
        for (var j = i + 1; j < sizeType.length; j++) {
            if (sizeType[i] == sizeType[j]) {
                number += 1;
                n++;
            }
        }
        result += number + "x" + sizeType[i] + ",";
        i = i + n;
    }
    result = result.substring(0, result.length - 1);
    $("#totalSizeType").html('');
    $("#totalSizeType").html(result);
    $("#containerTotle").val(result);
}
/**
 * 用于跳转到该页面时 自动加载到请输入柜型（id为gd_ctNumType）的柜型信息
 */
function Gd_ctNumTypeMsg() {
    var sizeType1 = $("#tril_goodsList tr:gt(0)").find("td:eq(8)");
    var sizeTypeStr = "";
    $.each(sizeType1, function (i, n) {
        sizeTypeStr += $(n).text() + ",";
    });
    sizeTypeStr = sizeTypeStr.substring(0, sizeTypeStr.length - 1);
    var sizeType = sizeTypeStr.split(",");
    //去重
    var tempArray = [];
    var tempObj = {};
    for (var i = 0; i < sizeType.length; i++) {
        if (!tempObj[sizeType[i]]) {
            tempArray.push(sizeType[i]);
            tempObj[sizeType[i]] = 1;
        }
    }
    containers = new Array();
    sizeType = arraySort(tempArray);
    for (var i = 0; i < sizeType.length; i++) {
        var tempObj = new Object();
//		 var tempStr = sizeType[i].trim();
        var tempStr = sizeType[i] + "";
        tempObj.size = tempStr.substring(4, 6);
        tempObj.type = tempStr.substring(7);
        tempObj.index = tempStr.substring(0, 1);
        containers.push(tempObj);
    }
    return containers;
}
/**
 * 自定义数组的排序 用于柜型（比如1号柜-20'HD）排序 （先柜型，尺寸，柜号）
 */
function arraySort(array) {
//	var typeArr = ["HD","HQ","GP"];
    var typeArr = ["HD", "HQ", "GP", "OT", "RF", "FR"];
    var newArr = [];
    var tempStr = "";
    for (var i = 0; i < typeArr.length; i++) {
        var tempArr = [];
        //柜号排
        for (var j = 0; j < array.length; j++) {
            if (typeArr[i] == array[j].substring(7)) {
                tempArr.push(array[j]);
            }
        }
        if (tempArr.length == 0) {
            continue;
        }
        //柜型排序
        tempArr.sort();
        //柜尺寸排序
        for (var m = 0; m < tempArr.length - 1; m++) {
            for (var n = m + 1; n < tempArr.length; n++) {
                if (tempArr[m].substring(4) == tempArr[n].substring(4)) {
                    var temp = tempArr[n];
                    tempArr[n] = tempArr[m + 1];
                    tempArr[m + 1] = temp;
                    m++;
                }
            }
        }
        tempStr += tempArr.join(",");
        tempStr += ",";
    }
    tempStr = tempStr.substring(0, tempStr.length - 1);
    newArr = tempStr.split(",");
    return newArr;
}
function copygoodes(obj) {
    var tr = $(obj).parent().parent();
    var trhtml = tr.html();
    var trnew = $("<tr onclick='editgoodesad(this)'>").html(trhtml);
    $("#tril_goodsList").append(trnew);
    $("#tril_goodsList tr:last td:eq(3)").text("");//清除复制时最新记录的id的值
    countTotalSizeType();
}

function delgoodes(obj) {
    var tr = $(obj).parent().parent();
    tr.remove();
    countTotalSizeType();
}

function editgoodesad(tr) {
    //展示装运信息表格和确认按钮
    $("#trail_info_shipmen").show();
    $("#confirmgoodesadBtn").show();
    $("#containersInfo").show();
    $("#trailContainersInfo").show();

    if (window.event.srcElement.tagName == "TD") {
    } else {
        if (updateData) {
            $(updateData).removeClass("ui-state-highlight");
        }
        // 修改数据时临时变量，用于确定修改确定修改的记录行
        updateData = tr;
        $(tr).addClass("ui-state-highlight");
        var table = $("#tril_goodsList");
        var values = $(tr).find("td");
        $.each(table.find("tr").first().find("td"), function (i, n) {
            var value = $(values[i]).text();
            var zhsj = $(values[10]).text();
            if (value == undefined || value == null) {
                value = "";
            }
            $("#gd_" + $(n).attr("lang")).val(value);
            if (i == 8) {
                $("#gd_ctNumType_show").html(value);
            }
            var gd_zhDate = zhsj.substring(0, 10);
            var gd_zhTime = zhsj.substring(11, 13);
            $("#gd_zhDate").val(gd_zhDate);
            $("#gd_zhTime").val(gd_zhTime);
            if (i == 4) {
                var contacter_address_val = $(values[18]).text();
                $("#gd_contacter_address_val").val(contacter_address_val);
            }
        });
    }
    //countSizeType($("#gd_ctNumType"),"");
    countSizeType($("#gd_ctNumType_show"), "", "");
    $("#orderSave").hide();
    $("#tril_goodsList_title").hide();
    $("#tril_goodsList").hide();
}

/**显示上传对话框**/
function upload() {
    var param = {
        id: '#dialog001'
    };
    jw.dialog(param);
}
function cancleUpload() {
    var fileId = $("#soid").val();
    if (fileId) {
        $.ajax({
            url: "attach-cancleFile.do?fileId=" + fileId + "&businessType=T",
            success: function (data) {
                var msg = $.parseJSON(data.msg);
                jw.alert(msg.msg);
                if (msg.state == "1") {
                    //$("#uploadForm").attr("enctype","multipart/form-data");
                    $("#so table tr:eq(1) td:eq(0)").html("上传");
                    $("#soid").val("");
                }
            }
        });
    } else {
        jw.alert("没有已上传文件！");
    }
}
$(document).ready(function () {
//	$("#businessForm").validationEngine();
    try {
        ct_type = getDropdownValueCt('../base/dropdown-ctType.do');
        ct_size = getDropdownValueCt('../base/dropdown-ctSize.do');
        ct_type = [" "].concat(ct_type);
        initDropdown();
        $('input[id=deleteType]').attr('disabled', true);

        autocom(0);

        // 建议装柜时间
//		$("#gd_zhDate").datetimepicker({showMinute:false});
        $("#gd_zhDate").datepicker();
        // 拖车业务代理
        $("#trial_sup_id").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "business-findCompanysByNameType.do",
                    dataType: "json",
                    type: "post",
                    data: {
                        com_type: "CC", sup_type: "C",// 拖车业务类型
                        com_name: request.term
                    },
                    success: function (data) {
                        response($.map(data.companys, function (item) {
                            return {
                                id: item.id, name: item.name,
                                value: item.name
                            };
                        }));
                    }
                });
            },
            minLength: 0,
            select: function (event, ui) {
                $("#trial_sup").val(ui.item.id);
            },
            change: function (event, ui) {
                var trial_sup_id = $("#trial_sup_id").val();
                $.ajax({
                    url: "business-findCompanysByNameTypeIsRight.do",
                    dataType: "json",
                    type: "post",
                    data: {
                        com_type: "CC", sup_type: "C",//订舱业务类型
                        com_name: trial_sup_id
                    },
                    success: function (data) {
                        if (data.companys == "") {
                            alert("请在拖车业务代理人的下拉框中选择拖车业务代理人!");
                            $("#trial_sup_id").focus();
                        } else {
                            var trial_sup_id = $("#trial_sup_id").val();
                            var trial_sup = $("#trial_sup").val();
                            if (trial_sup_id != "" && trial_sup == "") {
                                alert("请在拖车业务代理人的下拉框中选择拖车业务代理人!");
                                $("#trial_sup_id").focus();
                            }
                        }
                    }
                });
            }
        });

        $("#trial_sup_id").bind("click", function () {
            $(this).autocomplete('search', '');
        });
        /* 初始化上传功能 */
        var option = {
            success: function showResponse(responseText,
                                           statusText, xhr, $form) {
                jw.close();
                //$("#upload_so").css("display", "block");
                //$("#so").css("display", "none");
                var responseText = eval("(" + responseText + ")");
                $("#soid").val(responseText.attachment.id);
                $("#so table tr:eq(1) td:eq(0)").html(responseText.attachment.name);
                //$("#soValue").html(responseText.attachment.name);
                //$("#uploadForm").attr("enctype","");
            }
        };
        $("#uploadForm").ajaxForm(option);
    } catch (e) {
    }

    /**
     * 检测时间是否超过24
     */
    $("#gd_zhTime").focusout(function () {
        var gd_zhTime = $("#gd_zhTime").val();
        if (gd_zhTime > 24) {
            jw.confirm('<div><p style="font-style: normal;font-size: 16px;color:red;">您填写的小时数不能大于24!</p></div>', function () {
                $(this).dialog('destroy');
                $("#gd_zhTime").val("");
                $("#gd_zhTime").focus();
                return;
            }, function () {
                $("#gd_zhTime").val("");
                $("#gd_zhTime").focus();
                return;
            });
        }
    });


    /**
     * 检测日期类型yyyy-mm-dd
     * @param str
     * @returns {Boolean}
     */
    $("#gd_zhDate").change(function () {
        var gd_zhDate = $("#gd_zhDate").val();
        var r = gd_zhDate.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);//检测时间类型
        if (r == null) {
            jw.confirm('<div><p style="font-style: normal;font-size: 16px;color:red;">您输入的时间格式不正确,请您在时间控件中选择时间!</p></div>', function () {
                $(this).dialog('destroy');
                $("#gd_zhDate").val("");
                $("#gd_zhDate").focus();
                return;
            }, function () {
                $("#gd_zhDate").val("");
                $("#gd_zhDate").focus();
                return;
            });
        }
    });
    function strDateTime(str) {
        var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
        if (r == null) {
            return false;
        } else {
            return true;
        }
    }

});


function autocom(n) {
    n = (n == 0 ? "" : "_" + n);
    // 装柜工厂名称
    $("#gd_contacter_company" + n).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "contacter-findListByName.do",
                dataType: "json",
                type: "post",
                data: {name: request.term},
                success: function (data) {
                    response($.map(data.contacters, function (item) {
                        return {
                            id: item.id,
                            username: item.name,
                            phone: item.phone,
                            label: item.name + " - " + item.company,
                            value: item.company,
                            address: item.address,
                            city: item.city,
                            area: item.area,
                            town: item.town
                        };
                    }));
                }
            });
        }, minLength: 1, select: function (event, ui) {
            $("#gd_contacter_company" + n).val(ui.item.value);
            $("#gd_contacter_phone" + n).val(ui.item.phone);
            $("#gd_contacter_name" + n).val(ui.item.username);
            $("#gd_contacter_city" + n).val(ui.item.city);
            $("#gd_contacter_area" + n).val(ui.item.area);
            $("#gd_contacter_town" + n).val(ui.item.town);
            $("#gd_contacter_address_val" + n).val(ui.item.address);
            $("#gd_contacter_id" + n).val(ui.item.id);
        }
    });
}

function addTest() {
    var _len = $("#trial_gd_input tr").length;
    $("#trial_gd_input").append("<tr id=" + (_len - 5) + ">"
        + "<td class=\"add_line\" style=\"text-align:right\">地址" + (_len - 4) + "：</td>"
        + "<td class=\"add_line\"><input onclick=\"javascript:autocom(" + (_len - 5) + ");\"  type=\"text\" id=\"gd_contacter_company_" + (_len - 5) + "\" class=\"textInput validate[required] custom_wbf\"/></td>"
        + "<td class=\"add_line\" colspan=\"2\" style='white-space:nowrap;'>"
        + "<input style='width:50px;margin-left:5px;' type=\"text\" id=\"gd_contacter_city_" + (_len - 5) + "\" placeholder=\"--市--\" class=\"textInput validate[required]\" onfocus=\"dropdown(this, '2')\"/>&nbsp;"
        + "<input style='width:50px;' type=\"text\" id=\"gd_contacter_area_" + (_len - 5) + "\" placeholder=\"--县(区)--\" class=\"textInput validate[required]\" onfocus=\"dropdown(this, '3')\"/>&nbsp;"
        + "<input style='width:100px;' type=\"text\" id=\"gd_contacter_town_" + (_len - 5) + "\" placeholder=\"--镇(街道)--\" class=\"textInput validate[required]\" onfocus=\"dropdown(this, '4')\"/>&nbsp;"
        + "<input style='width:150px;'  type=\"text\" id=\"gd_contacter_address_val_" + (_len - 5) + "\" placeholder=\"--详细地址--\" class=\"textInput validate[required]\"/>"
        + "</td>"
        + "<td class=\"add_line\" colspan=\"2\" style='white-space:nowrap;'>"
        + "<input type=\"text\" id=\"gd_zhDate_" + (_len - 5) + "\" class=\"textInput validate[required]\" style='width:80px;margin-left:5px;'/>&nbsp;"
        + "<input type=\"text\" id=\"gd_zhTime_" + (_len - 5) + "\" class=\"textInput validate[required]\" maxlength=\"2\" style='width:30px;'/>"
        + "<font color=\"red\">:00</font>"
        + "</td>"
        + "<td class=\"add_line\"><input  type=\"text\" id=\"gd_contacter_name_" + (_len - 5) + "\" style='width:70px;' class=\"textInput validate[required] custom_wbf\"/></td>"
        + "<td class=\"add_line\"><input class=\"textInput custom_wbf\" type=\"text\" id=\"gd_contacter_phone_" + (_len - 5) + "\" style='width:90px;' /></td>"
        + "<td class=\"add_line\"><input id='gd_ctNumType_" + (_len - 5) + "' type='text' readonly='readonly' class='ui-state-default ui-corner-all validate[required] custom_wbf' style='width: 180px;'  />&nbsp;&nbsp;全选:<input type=\"checkbox\" id=\"selectall_checkbox_" + (_len - 5) + "\" onclick=\"selectAll(this);\" /></td>"
//   + "<td class=\"add_line\" style=\"text-align:center\"><input type=\"hidden\" id=\"gd_contacter_id_"+(_len-5)+"\" /><a href='javascript:;' onclick=\'deleteTest("+(_len-5)+")\'>删除</a></td>"
        + "<td class=\"add_line\" style=\"display:none;\" ><span id=\"gd_ctNumType_show_" + (_len - 5) + "\"></span></td>"
        + "<td class=\"add_line\" style=\"text-align:center\"><input type=\"hidden\" id=\"gd_contacter_id_" + (_len - 5) + "\" /><input type=\"button\" style=\"background-color: #94e7ff;border:1px solid #6acce8 ;cursor: pointer;border-radius:3px\" value=\"删除\" onclick=\'deleteTest(" + (_len - 5) + ")\' /></td>"
        + "</tr>");
    $("#gd_zhDate_" + (_len - 5)).datepicker();//每次增加一条记录初始化装柜时间控件
    initCtNumTypeDropdown(containers);
}

function deleteTest(index) {
    var _len = $("#trial_gd_input tr").length;
    $("tr[id='" + index + "']").remove();//删除当前行
    for (var i = index + 1, j = _len; i < j; i++) {
        //var nextTxtVal = $("#desc"+i).val();
        var temp = i - 1;
        $("tr[id=\'" + i + "\']")
            .replaceWith("<tr id=" + temp + ">"
                + "<td class=\"add_line\" style=\"text-align:right\">地址" + i + "：</td>"
                + "<td class=\"add_line\"><input onclick=\"javascript:autocom(" + temp + ");\"  type=\"text\" id=\"gd_contacter_company_" + temp + "\" class=\"textInput validate[required] custom_wbf\"/></td>"
                + "<td class=\"add_line\" colspan=\"2\" style='white-space:nowrap;'>"
                + "<input style='width:50px;margin-left:5px;' type=\"text\" id=\"gd_contacter_city_" + temp + "\" class=\"textInput validate[required]\" onfocus=\"dropdown(this, '2')\"/>&nbsp;"
                + "<input style='width:50px;' type=\"text\" id=\"gd_contacter_area_" + temp + "\" class=\"textInput validate[required]\" onfocus=\"dropdown(this, '3')\"/>&nbsp;"
                + "<input style='width:100px;' type=\"text\" id=\"gd_contacter_town_" + temp + "\" class=\"textInput validate[required]\" onfocus=\"dropdown(this, '4')\"/>&nbsp;"
                + "<input style='width:150px;'  type=\"text\" id=\"gd_contacter_address_val_" + temp + "\" class=\"textInput validate[required]\"/>"
                + "</td>"
                + "<td class=\"add_line\" colspan=\"2\" style='white-space:nowrap;'>"
                + "<input type=\"text\" id=\"gd_zhDate_" + temp + "\" class=\"textInput validate[required]\" style='width:80px;margin-left:5px;'/>&nbsp;"
                + "<input type=\"text\" id=\"gd_zhTime_" + temp + "\" class=\"textInput validate[required]\" maxlength=\"2\" style='width:30px;'/>"
                + "<font color=\"red\">:00</font>"
                + "</td>"
                + "<td class=\"add_line\"><input  type=\"text\" id=\"gd_contacter_name_" + temp + "\" style='width:70px;' class=\"textInput validate[required] custom_wbf\"/></td>"
                + "<td class=\"add_line\"><input class=\"textInput custom_wbf\" type=\"text\" id=\"gd_contacter_phone_" + temp + "\" style='width:90px;' /></td>"
                + "<td class=\"add_line\"><input id='gd_ctNumType_" + temp + "' type='text' readonly='readonly' class='ui-state-default ui-corner-all validate[required] custom_wbf' style='width: 180px;'  />&nbsp;&nbsp;全选:<input type=\"checkbox\" id=\"selectall_checkbox_" + temp + "\" onclick=\"selectAll(this);\"/></td>"
                //   + "<td class=\"add_line\" style=\"text-align:center\"><input type=\"hidden\" id=\"gd_contacter_id_"+temp+"\" /><a href='javascript:;' onclick=\'deleteTest("+temp+")\'>删除</a></td>"
                + "<td class=\"add_line\" style=\"display:none;\" ><span id=\"gd_ctNumType_show_" + temp + "\"></span></td>"
                + "<td class=\"add_line\" style=\"text-align:center\"><input type=\"hidden\" id=\"gd_contacter_id_" + temp + "\" /><input type=\"button\" style=\"background-color: #94e7ff;border:1px solid #6acce8 ;cursor: pointer;border-radius:3px\" value=\"删除\" onclick=\'deleteTest(" + temp + ")\' /></td>"
                + "</tr>");
    }
}


//函数说明：合并指定表格（表格id为_w_table_id）指定列（列数为_w_table_colnum）的相同文本的相邻单元格
//参数说明：_w_table_id 为需要进行合并单元格的表格的id。如在HTMl中指定表格 id="data" ，此参数应为 #data 
//参数说明：_w_table_colnum 为需要合并单元格的所在列。为数字，从最左边第一列为1开始算起。
function _w_table_rowspan(_w_table_id, _w_table_colnum) {
    _w_table_firsttd = "";
    _w_table_currenttd = "";
    _w_table_SpanNum = 0;
    _w_table_Obj = $(_w_table_id + " tr td:nth-child(" + _w_table_colnum + ")");
    _w_table_Obj.each(function (i) {
        if (i == 0) {
            _w_table_firsttd = $(this);
            _w_table_SpanNum = 1;
        } else {
            _w_table_currenttd = $(this);
            if (_w_table_firsttd.text() == _w_table_currenttd.text()) {
                _w_table_SpanNum++;
                _w_table_currenttd.hide(); //remove();
                _w_table_firsttd.attr("rowSpan", _w_table_SpanNum);
            } else {
                _w_table_firsttd = $(this);
                _w_table_SpanNum = 1;
            }
        }
    });
}

//函数说明：合并指定表格（表格id为_w_table_id）指定行（行数为_w_table_rownum）的相同文本的相邻单元格
//参数说明：_w_table_id 为需要进行合并单元格的表格id。如在HTMl中指定表格 id="data" ，此参数应为 #data 
//参数说明：_w_table_rownum 为需要合并单元格的所在行。其参数形式请参考jQuery中nth-child的参数。
//        如果为数字，则从最左边第一行为1开始算起。
//        "even" 表示偶数行
//        "odd" 表示奇数行
//        "3n+1" 表示的行数为1、4、7、10.......
//参数说明：_w_table_maxcolnum 为指定行中单元格对应的最大列数，列数大于这个数值的单元格将不进行比较合并。
//        此参数可以为空，为空则指定行的所有单元格要进行比较合并。
function _w_table_colspan(_w_table_id, _w_table_rownum, _w_table_maxcolnum) {
    if (_w_table_maxcolnum == void 0) {
        _w_table_maxcolnum = 0;
    }
    _w_table_firsttd = "";
    _w_table_currenttd = "";
    _w_table_SpanNum = 0;
    $(_w_table_id + " tr:nth-child(" + _w_table_rownum + ")").each(function (i) {
        _w_table_Obj = $(this).children();
        _w_table_Obj.each(function (i) {
            if (i == 0) {
                _w_table_firsttd = $(this);
                _w_table_SpanNum = 1;
            } else if ((_w_table_maxcolnum > 0) && (i > _w_table_maxcolnum)) {
                return "";
            } else {
                _w_table_currenttd = $(this);
                if (_w_table_firsttd.text() == _w_table_currenttd.text()) {
                    _w_table_SpanNum++;
                    _w_table_currenttd.hide(); //remove();
                    _w_table_firsttd.attr("colSpan", _w_table_SpanNum);
                } else {
                    _w_table_firsttd = $(this);
                    _w_table_SpanNum = 1;
                }
            }
        });
    });
}